<?php
/**
 * Created by PhpStorm.
 * User: 14775
 * Date: 2017/9/27
 * Time: 11:38
 */

namespace Api\Controller;


use Common\Controller\HomebaseController;
use Common\Model\PromotionCouponCodeModel;
use Common\Model\PromotionCouponModel;

class CouponController extends HomebaseController
{

    public function usecoupon()
    {

        $api_users = C('API_USERS');
        //验证
        $params = I('');
        $api_sign = $params['sign'];
        $api_appid = $params['apiid'];
        $api_appsecret = $api_users[$api_appid];

        unset($params['sign']);
        $params['apisecret'] = $api_appsecret;
        ksort($params);
        $str_parmas = http_build_query($params);

        if ($api_sign == md5($str_parmas)) {

            //=============使用优惠券==========>>>>>>>>>>>>
            $coupon_model = new PromotionCouponModel();
            $result = $coupon_model->useCoupon($params['code']);
            $data = array(
                'message' => $result['message'],
                'status' => $result['code'],
                'data'=>$result['data']
            );
            $this->ajaxReturn($data);
            //<<<<<<<<<<<<<<=====================================
        } else {
            $this->ajaxReturn(array('status' => 0, 'message' => '验签失败'));
        }
        $this->ajaxReturn(array('status' => 0, 'message' => '系统错误'));
    }

}